1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package sun.security.provider.certpath.ldap;
27
28 import java.io.ByteArrayInputStream;
29 import java.io.IOException;
30 import java.math.BigInteger;
31 import java.net.URI;
32 import java.util.*;
33 import javax.naming.Context;
34 import javax.naming.NamingEnumeration;
35 import javax.naming.NamingException;
36 import javax.naming.NameNotFoundException;
37 import javax.naming.directory.Attribute;
38 import javax.naming.directory.Attributes;
39 import javax.naming.directory.BasicAttributes;
40 import javax.naming.directory.DirContext;
41 import javax.naming.directory.InitialDirContext;
42
43 import java.security.*;
44 import java.security.cert.Certificate;
45 import java.security.cert.*;
46 import javax.security.auth.x500.X500Principal;
47
48 import sun.misc.HexDumpEncoder;
49 import sun.security.provider.certpath.X509CertificatePair;
50 import sun.security.util.Cache;
51 import sun.security.util.Debug;
52 import sun.security.x509.X500Name;
53 import sun.security.action.GetPropertyAction;
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106 public class LDAPCertStore extends CertStoreSpi {
107
108 private static final Debug debug = Debug.getInstance("certpath");
109
110 private final static boolean DEBUG = false;
111
112
113
114
115 private static final String USER_CERT = "userCertificate;binary";
116 private static final String CA_CERT = "cACertificate;binary";
117 private static final String CROSS_CERT = "crossCertificatePair;binary";
118 private static final String CRL = "certificateRevocationList;binary";
119 private static final String ARL = "authorityRevocationList;binary";
120 private static final String DELTA_CRL = "deltaRevocationList;binary";
121
122
123 private final static String[] STRING0 = new String[0];
124
125 private final static byte[][] BB0 = new byte[0][];
126
127 private final static Attributes EMPTY_ATTRIBUTES = new BasicAttributes();
128
129
130 private final static int DEFAULT_CACHE_SIZE = 750;
131 private final static int DEFAULT_CACHE_LIFETIME = 30;
132
133 private final static int LIFETIME;
134
135 private final static String PROP_LIFETIME =
136 "sun.security.certpath.ldap.cache.lifetime";
137
138 static {
139 String s = AccessController.doPrivileged(
140 new GetPropertyAction(PROP_LIFETIME));
141 if (s != null) {
142 LIFETIME = Integer.parseInt(s);
143 } else {
144 LIFETIME = DEFAULT_CACHE_LIFETIME;
145 }
146 }
147
148
149
150
151
152 private CertificateFactory cf;
153
154
155
156 private DirContext ctx;
157
158
159
160
161 private boolean prefetchCRLs = false;
162
163 private final Cache valueCache;
164
165 private int cacheHits = 0;
166 private int cacheMisses = 0;
167 private int requests = 0;
168
169
170
171
172
173
174
175
176
177
178 public LDAPCertStore(CertStoreParameters params)
179 throws InvalidAlgorithmParameterException {
180 super(params);
181 if (!(params instanceof LDAPCertStoreParameters))
182 throw new InvalidAlgorithmParameterException(
183 "parameters must be LDAPCertStoreParameters");
184
185 LDAPCertStoreParameters lparams = (LDAPCertStoreParameters) params;
186
187
188 createInitialDirContext(lparams.getServerName(), lparams.getPort());
189
190
191 try {
192 cf = CertificateFactory.getInstance("X.509");
193 } catch (CertificateException e) {
194 throw new InvalidAlgorithmParameterException(
195 "unable to create CertificateFactory for X.509");
196 }
197 if (LIFETIME == 0) {
198 valueCache = Cache.newNullCache();
199 } else if (LIFETIME < 0) {
200 valueCache = Cache.newSoftMemoryCache(DEFAULT_CACHE_SIZE);
201 } else {
202 valueCache = Cache.newSoftMemoryCache(DEFAULT_CACHE_SIZE, LIFETIME);
203 }
204 }
205
206
207
208
209
210 private static final Cache certStoreCache = Cache.newSoftMemoryCache(185);
211 static synchronized CertStore getInstance(LDAPCertStoreParameters params)
212 throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
213 CertStore lcs = (CertStore) certStoreCache.get(params);
214 if (lcs == null) {
215 lcs = CertStore.getInstance("LDAP", params);
216 certStoreCache.put(params, lcs);
217 } else {
218 if (debug != null) {
219 debug.println("LDAPCertStore.getInstance: cache hit");
220 }
221 }
222 return lcs;
223 }
224
225
226
227
228
229
230
231
232 private void createInitialDirContext(String server, int port)
233 throws InvalidAlgorithmParameterException {
234 String url = "ldap://" + server + ":" + port;
235 Hashtable<String,Object> env = new Hashtable<String,Object>();
236 env.put(Context.INITIAL_CONTEXT_FACTORY,
237 "com.sun.jndi.ldap.LdapCtxFactory");
238 env.put(Context.PROVIDER_URL, url);
239 try {
240 ctx = new InitialDirContext(env);
241
242
243
244
245 Hashtable<?,?> currentEnv = ctx.getEnvironment();
246 if (currentEnv.get(Context.REFERRAL) == null) {
247 ctx.addToEnvironment(Context.REFERRAL, "follow");
248 }
249 } catch (NamingException e) {
250 if (debug != null) {
251 debug.println("LDAPCertStore.engineInit about to throw "
252 + "InvalidAlgorithmParameterException");
253 e.printStackTrace();
254 }
255 Exception ee = new InvalidAlgorithmParameterException
256 ("unable to create InitialDirContext using supplied parameters");
257 ee.initCause(e);
258 throw (InvalidAlgorithmParameterException)ee;
259 }
260 }
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278 private class LDAPRequest {
279
280 private final String name;
281 private Map<String, byte[][]> valueMap;
282 private final List<String> requestedAttributes;
283
284 LDAPRequest(String name) {
285 this.name = name;
286 requestedAttributes = new ArrayList<String>(5);
287 }
288
289 String getName() {
290 return name;
291 }
292
293 void addRequestedAttribute(String attrId) {
294 if (valueMap != null) {
295 throw new IllegalStateException("Request already sent");
296 }
297 requestedAttributes.add(attrId);
298 }
299
300
301
302
303
304
305
306
307
308 byte[][] getValues(String attrId) throws NamingException {
309 if (DEBUG && ((cacheHits + cacheMisses) % 50 == 0)) {
310 System.out.println("Cache hits: " + cacheHits + "; misses: "
311 + cacheMisses);
312 }
313 String cacheKey = name + "|" + attrId;
314 byte[][] values = (byte[][])valueCache.get(cacheKey);
315 if (values != null) {
316 cacheHits++;
317 return values;
318 }
319 cacheMisses++;
320 Map<String, byte[][]> attrs = getValueMap();
321 values = attrs.get(attrId);
322 return values;
323 }
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339 private Map<String, byte[][]> getValueMap() throws NamingException {
340 if (valueMap != null) {
341 return valueMap;
342 }
343 if (DEBUG) {
344 System.out.println("Request: " + name + ":" + requestedAttributes);
345 requests++;
346 if (requests % 5 == 0) {
347 System.out.println("LDAP requests: " + requests);
348 }
349 }
350 valueMap = new HashMap<String, byte[][]>(8);
351 String[] attrIds = requestedAttributes.toArray(STRING0);
352 Attributes attrs;
353 try {
354 attrs = ctx.getAttributes(name, attrIds);
355 } catch (NameNotFoundException e) {
356
357
358 attrs = EMPTY_ATTRIBUTES;
359 }
360 for (String attrId : requestedAttributes) {
361 Attribute attr = attrs.get(attrId);
362 byte[][] values = getAttributeValues(attr);
363 cacheAttribute(attrId, values);
364 valueMap.put(attrId, values);
365 }
366 return valueMap;
367 }
368
369
370
371
372 private void cacheAttribute(String attrId, byte[][] values) {
373 String cacheKey = name + "|" + attrId;
374 valueCache.put(cacheKey, values);
375 }
376
377
378
379
380
381
382 private byte[][] getAttributeValues(Attribute attr)
383 throws NamingException {
384 byte[][] values;
385 if (attr == null) {
386 values = BB0;
387 } else {
388 values = new byte[attr.size()][];
389 int i = 0;
390 NamingEnumeration<?> enum_ = attr.getAll();
391 while (enum_.hasMore()) {
392 Object obj = enum_.next();
393 if (debug != null) {
394 if (obj instanceof String) {
395 debug.println("LDAPCertStore.getAttrValues() "
396 + "enum.next is a string!: " + obj);
397 }
398 }
399 byte[] value = (byte[])obj;
400 values[i++] = value;
401 }
402 }
403 return values;
404 }
405
406 }
407
408
409
410
411
412
413
414
415
416
417
418
419 private Collection<X509Certificate> getCertificates(LDAPRequest request,
420 String id, X509CertSelector sel) throws CertStoreException {
421
422
423 byte[][] encodedCert;
424 try {
425 encodedCert = request.getValues(id);
426 } catch (NamingException namingEx) {
427 throw new CertStoreException(namingEx);
428 }
429
430 int n = encodedCert.length;
431 if (n == 0) {
432 return Collections.<X509Certificate>emptySet();
433 }
434
435 List<X509Certificate> certs = new ArrayList<X509Certificate>(n);
436
437 for (int i = 0; i < n; i++) {
438 ByteArrayInputStream bais = new ByteArrayInputStream(encodedCert[i]);
439 try {
440 Certificate cert = cf.generateCertificate(bais);
441 if (sel.match(cert)) {
442 certs.add((X509Certificate)cert);
443 }
444 } catch (CertificateException e) {
445 if (debug != null) {
446 debug.println("LDAPCertStore.getCertificates() encountered "
447 + "exception while parsing cert, skipping the bad data: ");
448 HexDumpEncoder encoder = new HexDumpEncoder();
449 debug.println(
450 "[ " + encoder.encodeBuffer(encodedCert[i]) + " ]");
451 }
452 }
453 }
454
455 return certs;
456 }
457
458
459
460
461
462
463
464
465
466
467 private Collection<X509CertificatePair> getCertPairs(
468 LDAPRequest request, String id) throws CertStoreException {
469
470
471 byte[][] encodedCertPair;
472 try {
473 encodedCertPair = request.getValues(id);
474 } catch (NamingException namingEx) {
475 throw new CertStoreException(namingEx);
476 }
477
478 int n = encodedCertPair.length;
479 if (n == 0) {
480 return Collections.<X509CertificatePair>emptySet();
481 }
482
483 List<X509CertificatePair> certPairs =
484 new ArrayList<X509CertificatePair>(n);
485
486 for (int i = 0; i < n; i++) {
487 try {
488 X509CertificatePair certPair =
489 X509CertificatePair.generateCertificatePair(encodedCertPair[i]);
490 certPairs.add(certPair);
491 } catch (CertificateException e) {
492 if (debug != null) {
493 debug.println(
494 "LDAPCertStore.getCertPairs() encountered exception "
495 + "while parsing cert, skipping the bad data: ");
496 HexDumpEncoder encoder = new HexDumpEncoder();
497 debug.println(
498 "[ " + encoder.encodeBuffer(encodedCertPair[i]) + " ]");
499 }
500 }
501 }
502
503 return certPairs;
504 }
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522 private Collection<X509Certificate> getMatchingCrossCerts(
523 LDAPRequest request, X509CertSelector forward,
524 X509CertSelector reverse)
525 throws CertStoreException {
526
527 Collection<X509CertificatePair> certPairs =
528 getCertPairs(request, CROSS_CERT);
529
530
531 ArrayList<X509Certificate> matchingCerts =
532 new ArrayList<X509Certificate>();
533 for (X509CertificatePair certPair : certPairs) {
534 X509Certificate cert;
535 if (forward != null) {
536 cert = certPair.getForward();
537 if ((cert != null) && forward.match(cert)) {
538 matchingCerts.add(cert);
539 }
540 }
541 if (reverse != null) {
542 cert = certPair.getReverse();
543 if ((cert != null) && reverse.match(cert)) {
544 matchingCerts.add(cert);
545 }
546 }
547 }
548 return matchingCerts;
549 }
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572 public synchronized Collection<X509Certificate> engineGetCertificates
573 (CertSelector selector) throws CertStoreException {
574 if (debug != null) {
575 debug.println("LDAPCertStore.engineGetCertificates() selector: "
576 + String.valueOf(selector));
577 }
578
579 if (selector == null) {
580 selector = new X509CertSelector();
581 }
582 if (!(selector instanceof X509CertSelector)) {
583 throw new CertStoreException("LDAPCertStore needs an X509CertSelector " +
584 "to find certs");
585 }
586 X509CertSelector xsel = (X509CertSelector) selector;
587 int basicConstraints = xsel.getBasicConstraints();
588 String subject = xsel.getSubjectAsString();
589 String issuer = xsel.getIssuerAsString();
590 HashSet<X509Certificate> certs = new HashSet<X509Certificate>();
591 if (debug != null) {
592 debug.println("LDAPCertStore.engineGetCertificates() basicConstraints: "
593 + basicConstraints);
594 }
595
596
597
598
599
600
601 if (subject != null) {
602 if (debug != null) {
603 debug.println("LDAPCertStore.engineGetCertificates() "
604 + "subject is not null");
605 }
606 LDAPRequest request = new LDAPRequest(subject);
607 if (basicConstraints > -2) {
608 request.addRequestedAttribute(CROSS_CERT);
609 request.addRequestedAttribute(CA_CERT);
610 request.addRequestedAttribute(ARL);
611 if (prefetchCRLs) {
612 request.addRequestedAttribute(CRL);
613 }
614 }
615 if (basicConstraints < 0) {
616 request.addRequestedAttribute(USER_CERT);
617 }
618
619 if (basicConstraints > -2) {
620 certs.addAll(getMatchingCrossCerts(request, xsel, null));
621 if (debug != null) {
622 debug.println("LDAPCertStore.engineGetCertificates() after "
623 + "getMatchingCrossCerts(subject,xsel,null),certs.size(): "
624 + certs.size());
625 }
626 certs.addAll(getCertificates(request, CA_CERT, xsel));
627 if (debug != null) {
628 debug.println("LDAPCertStore.engineGetCertificates() after "
629 + "getCertificates(subject,CA_CERT,xsel),certs.size(): "
630 + certs.size());
631 }
632 }
633 if (basicConstraints < 0) {
634 certs.addAll(getCertificates(request, USER_CERT, xsel));
635 if (debug != null) {
636 debug.println("LDAPCertStore.engineGetCertificates() after "
637 + "getCertificates(subject,USER_CERT, xsel),certs.size(): "
638 + certs.size());
639 }
640 }
641 } else {
642 if (debug != null) {
643 debug.println
644 ("LDAPCertStore.engineGetCertificates() subject is null");
645 }
646 if (basicConstraints == -2) {
647 throw new CertStoreException("need subject to find EE certs");
648 }
649 if (issuer == null) {
650 throw new CertStoreException("need subject or issuer to find certs");
651 }
652 }
653 if (debug != null) {
654 debug.println("LDAPCertStore.engineGetCertificates() about to "
655 + "getMatchingCrossCerts...");
656 }
657 if ((issuer != null) && (basicConstraints > -2)) {
658 LDAPRequest request = new LDAPRequest(issuer);
659 request.addRequestedAttribute(CROSS_CERT);
660 request.addRequestedAttribute(CA_CERT);
661 request.addRequestedAttribute(ARL);
662 if (prefetchCRLs) {
663 request.addRequestedAttribute(CRL);
664 }
665
666 certs.addAll(getMatchingCrossCerts(request, null, xsel));
667 if (debug != null) {
668 debug.println("LDAPCertStore.engineGetCertificates() after "
669 + "getMatchingCrossCerts(issuer,null,xsel),certs.size(): "
670 + certs.size());
671 }
672 certs.addAll(getCertificates(request, CA_CERT, xsel));
673 if (debug != null) {
674 debug.println("LDAPCertStore.engineGetCertificates() after "
675 + "getCertificates(issuer,CA_CERT,xsel),certs.size(): "
676 + certs.size());
677 }
678 }
679 if (debug != null) {
680 debug.println("LDAPCertStore.engineGetCertificates() returning certs");
681 }
682 return certs;
683 }
684
685
686
687
688
689
690
691
692
693
694
695
696 private Collection<X509CRL> getCRLs(LDAPRequest request, String id,
697 X509CRLSelector sel) throws CertStoreException {
698
699
700 byte[][] encodedCRL;
701 try {
702 encodedCRL = request.getValues(id);
703 } catch (NamingException namingEx) {
704 throw new CertStoreException(namingEx);
705 }
706
707 int n = encodedCRL.length;
708 if (n == 0) {
709 return Collections.<X509CRL>emptySet();
710 }
711
712 List<X509CRL> crls = new ArrayList<X509CRL>(n);
713
714 for (int i = 0; i < n; i++) {
715 try {
716 CRL crl = cf.generateCRL(new ByteArrayInputStream(encodedCRL[i]));
717 if (sel.match(crl)) {
718 crls.add((X509CRL)crl);
719 }
720 } catch (CRLException e) {
721 if (debug != null) {
722 debug.println("LDAPCertStore.getCRLs() encountered exception"
723 + " while parsing CRL, skipping the bad data: ");
724 HexDumpEncoder encoder = new HexDumpEncoder();
725 debug.println("[ " + encoder.encodeBuffer(encodedCRL[i]) + " ]");
726 }
727 }
728 }
729
730 return crls;
731 }
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754 public synchronized Collection<X509CRL> engineGetCRLs(CRLSelector selector)
755 throws CertStoreException {
756 if (debug != null) {
757 debug.println("LDAPCertStore.engineGetCRLs() selector: "
758 + selector);
759 }
760
761 if (selector == null) {
762 selector = new X509CRLSelector();
763 }
764 if (!(selector instanceof X509CRLSelector)) {
765 throw new CertStoreException("need X509CRLSelector to find CRLs");
766 }
767 X509CRLSelector xsel = (X509CRLSelector) selector;
768 HashSet<X509CRL> crls = new HashSet<X509CRL>();
769
770
771 Collection<Object> issuerNames;
772 X509Certificate certChecking = xsel.getCertificateChecking();
773 if (certChecking != null) {
774 issuerNames = new HashSet<Object>();
775 X500Principal issuer = certChecking.getIssuerX500Principal();
776 issuerNames.add(issuer.getName(X500Principal.RFC2253));
777 } else {
778
779
780 issuerNames = xsel.getIssuerNames();
781 if (issuerNames == null) {
782 throw new CertStoreException("need issuerNames or certChecking to "
783 + "find CRLs");
784 }
785 }
786 for (Object nameObject : issuerNames) {
787 String issuerName;
788 if (nameObject instanceof byte[]) {
789 try {
790 X500Principal issuer = new X500Principal((byte[])nameObject);
791 issuerName = issuer.getName(X500Principal.RFC2253);
792 } catch (IllegalArgumentException e) {
793 continue;
794 }
795 } else {
796 issuerName = (String)nameObject;
797 }
798
799 Collection<X509CRL> entryCRLs = Collections.<X509CRL>emptySet();
800 if (certChecking == null || certChecking.getBasicConstraints() != -1) {
801 LDAPRequest request = new LDAPRequest(issuerName);
802 request.addRequestedAttribute(CROSS_CERT);
803 request.addRequestedAttribute(CA_CERT);
804 request.addRequestedAttribute(ARL);
805 if (prefetchCRLs) {
806 request.addRequestedAttribute(CRL);
807 }
808 try {
809 entryCRLs = getCRLs(request, ARL, xsel);
810 if (entryCRLs.isEmpty()) {
811
812
813 prefetchCRLs = true;
814 } else {
815 crls.addAll(entryCRLs);
816 }
817 } catch (CertStoreException e) {
818 if (debug != null) {
819 debug.println("LDAPCertStore.engineGetCRLs non-fatal error "
820 + "retrieving ARLs:" + e);
821 e.printStackTrace();
822 }
823 }
824 }
825
826
827
828 if (entryCRLs.isEmpty() || certChecking == null) {
829 LDAPRequest request = new LDAPRequest(issuerName);
830 request.addRequestedAttribute(CRL);
831 entryCRLs = getCRLs(request, CRL, xsel);
832 crls.addAll(entryCRLs);
833 }
834 }
835 return crls;
836 }
837
838
839 static LDAPCertStoreParameters getParameters(URI uri) {
840 String host = uri.getHost();
841 if (host == null) {
842 return new SunLDAPCertStoreParameters();
843 } else {
844 int port = uri.getPort();
845 return (port == -1
846 ? new SunLDAPCertStoreParameters(host)
847 : new SunLDAPCertStoreParameters(host, port));
848 }
849 }
850
851
852
853
854
855
856 private static class SunLDAPCertStoreParameters
857 extends LDAPCertStoreParameters {
858
859 private volatile int hashCode = 0;
860
861 SunLDAPCertStoreParameters(String serverName, int port) {
862 super(serverName, port);
863 }
864 SunLDAPCertStoreParameters(String serverName) {
865 super(serverName);
866 }
867 SunLDAPCertStoreParameters() {
868 super();
869 }
870 public boolean equals(Object obj) {
871 if (!(obj instanceof LDAPCertStoreParameters)) {
872 return false;
873 }
874 LDAPCertStoreParameters params = (LDAPCertStoreParameters) obj;
875 return (getPort() == params.getPort() &&
876 getServerName().equalsIgnoreCase(params.getServerName()));
877 }
878 public int hashCode() {
879 if (hashCode == 0) {
880 int result = 17;
881 result = 37*result + getPort();
882 result = 37*result + getServerName().toLowerCase().hashCode();
883 hashCode = result;
884 }
885 return hashCode;
886 }
887 }
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903 static class LDAPCertSelector extends X509CertSelector {
904
905 private X500Principal certSubject;
906 private X509CertSelector selector;
907 private X500Principal subject;
908
909
910
911
912
913
914
915
916
917 LDAPCertSelector(X509CertSelector selector, X500Principal certSubject,
918 String ldapDN) throws IOException {
919 this.selector = selector == null ? new X509CertSelector() : selector;
920 this.certSubject = certSubject;
921 this.subject = new X500Name(ldapDN).asX500Principal();
922 }
923
924
925
926 public X509Certificate getCertificate() {
927 return selector.getCertificate();
928 }
929 public BigInteger getSerialNumber() {
930 return selector.getSerialNumber();
931 }
932 public X500Principal getIssuer() {
933 return selector.getIssuer();
934 }
935 public String getIssuerAsString() {
936 return selector.getIssuerAsString();
937 }
938 public byte[] getIssuerAsBytes() throws IOException {
939 return selector.getIssuerAsBytes();
940 }
941 public X500Principal getSubject() {
942
943 return subject;
944 }
945 public String getSubjectAsString() {
946
947 return subject.getName();
948 }
949 public byte[] getSubjectAsBytes() throws IOException {
950
951 return subject.getEncoded();
952 }
953 public byte[] getSubjectKeyIdentifier() {
954 return selector.getSubjectKeyIdentifier();
955 }
956 public byte[] getAuthorityKeyIdentifier() {
957 return selector.getAuthorityKeyIdentifier();
958 }
959 public Date getCertificateValid() {
960 return selector.getCertificateValid();
961 }
962 public Date getPrivateKeyValid() {
963 return selector.getPrivateKeyValid();
964 }
965 public String getSubjectPublicKeyAlgID() {
966 return selector.getSubjectPublicKeyAlgID();
967 }
968 public PublicKey getSubjectPublicKey() {
969 return selector.getSubjectPublicKey();
970 }
971 public boolean[] getKeyUsage() {
972 return selector.getKeyUsage();
973 }
974 public Set<String> getExtendedKeyUsage() {
975 return selector.getExtendedKeyUsage();
976 }
977 public boolean getMatchAllSubjectAltNames() {
978 return selector.getMatchAllSubjectAltNames();
979 }
980 public Collection<List<?>> getSubjectAlternativeNames() {
981 return selector.getSubjectAlternativeNames();
982 }
983 public byte[] getNameConstraints() {
984 return selector.getNameConstraints();
985 }
986 public int getBasicConstraints() {
987 return selector.getBasicConstraints();
988 }
989 public Set<String> getPolicy() {
990 return selector.getPolicy();
991 }
992 public Collection<List<?>> getPathToNames() {
993 return selector.getPathToNames();
994 }
995
996 public boolean match(Certificate cert) {
997
998
999 selector.setSubject(certSubject);
1000 boolean match = selector.match(cert);
1001 selector.setSubject(subject);
1002 return match;
1003 }
1004 }
1005
1006
1007
1008
1009
1010 static class LDAPCRLSelector extends X509CRLSelector {
1011
1012 private X509CRLSelector selector;
1013 private Collection<X500Principal> certIssuers;
1014 private Collection<X500Principal> issuers;
1015 private HashSet<Object> issuerNames;
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025 LDAPCRLSelector(X509CRLSelector selector,
1026 Collection<X500Principal> certIssuers, String ldapDN)
1027 throws IOException {
1028 this.selector = selector == null ? new X509CRLSelector() : selector;
1029 this.certIssuers = certIssuers;
1030 issuerNames = new HashSet<Object>();
1031 issuerNames.add(ldapDN);
1032 issuers = new HashSet<X500Principal>();
1033 issuers.add(new X500Name(ldapDN).asX500Principal());
1034 }
1035
1036
1037 public Collection<X500Principal> getIssuers() {
1038
1039 return Collections.unmodifiableCollection(issuers);
1040 }
1041 public Collection<Object> getIssuerNames() {
1042
1043 return Collections.unmodifiableCollection(issuerNames);
1044 }
1045 public BigInteger getMinCRL() {
1046 return selector.getMinCRL();
1047 }
1048 public BigInteger getMaxCRL() {
1049 return selector.getMaxCRL();
1050 }
1051 public Date getDateAndTime() {
1052 return selector.getDateAndTime();
1053 }
1054 public X509Certificate getCertificateChecking() {
1055 return selector.getCertificateChecking();
1056 }
1057 public boolean match(CRL crl) {
1058
1059
1060 selector.setIssuers(certIssuers);
1061 boolean match = selector.match(crl);
1062 selector.setIssuers(issuers);
1063 return match;
1064 }
1065 }
1066 }